package com.university.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.university.mapper.FoodOrderMapper;
import com.university.pojo.cqe.command.CmdFoodOrder;
import com.university.pojo.cqe.query.FoodQuery;
import com.university.pojo.dto.FoodOrderDTO;
import com.university.pojo.entity.FoodOrder;
import com.university.service.FoodOrderService;
import com.university.utility.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Date: 2021/5/15 17:58
 * @Description:
 */
@Service
public class FoodOrderServiceImpl implements FoodOrderService {

    @Resource
    private FoodOrderMapper foodOrderMapper;

    @Override
    public void saveFoodOrder(List<CmdFoodOrder> list) {
        List<FoodOrder> foodList = ObjectUtils.convert(list, FoodOrder.class);
        Date orderDate = new Date();
        foodList.forEach(food -> food.setOrderDate(orderDate));
        foodOrderMapper.insertList(foodList);
    }

    @Override
    public List<FoodOrderDTO> userGetFoodOrder(FoodQuery query) {
        return foodOrderMapper.userGetFoodOrder(query);
    }

    @Override
    public IPage<FoodOrderDTO> adminGetFoodOrder(FoodQuery query) {
        IPage<FoodOrderDTO> page = new Page<>(query.getPage(), query.getPageSize());
        return foodOrderMapper.adminGetFoodOrderPage(page, query);
    }
}
